//
//  WPTitleViewButton.swift
//  WB
//
//  Created by 汪鹏 on 2017/1/3.
//  Copyright © 2017年 汪鹏. All rights reserved.
//

import UIKit

class WPTitleViewButton: UIButton {

    
    /// 重载构造函数
    ///
    /// - Parameter title: 标题
    init(title:String?) {
        super.init(frame: CGRect())
        
        // 1. 判断标题是否为空
        if title == nil {
            
            setTitle("首页", for: .normal)
            
        }else{
            
            setTitle(title! + "  ", for: .normal)
            
            setImage(UIImage(named: "navigationbar_arrow_down"), for: .normal)
            
            setImage(UIImage(named: "navigationbar_arrow_up"), for: .selected)
        }
        
        titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
        
        setTitleColor(UIColor.darkGray, for: .normal)
        
        sizeToFit()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    /// 重新布局安排的子控件
    override func layoutSubviews() {
        super.layoutSubviews()
        
        
        //titleLabel?.frame = CGRect(x: 0, y: (titleLabel?.frame.minY)!, width: (titleLabel?.frame.width)!, height: (titleLabel?.frame.height)!)
        titleLabel?.frame.origin.x = 0
        
         //imageView?.frame = CGRect(x: (titleLabel?.frame.maxX)!, y: (imageView?.frame.minY)!, width: (imageView?.frame.width)!, height: (imageView?.frame.height)!)
        imageView?.frame.origin.x = (titleLabel?.bounds.width)!
    }
    
}
